#------------------------------------------------------------------------------
# Set working directory where the script is located
#------------------------------------------------------------------------------

# R studio
setwd( dirname(rstudioapi::getActiveDocumentContext()$path) )
# R default : unccoment if you use default R
# setwd(getSrcDirectory(function(){})[1])
#------------------------------------------------------------------------------


needed_pack <- c("tidyverse", "data.table", "zoo", "tictoc", 
                "fst", "fixest", "PanelMatch", "patchwork", 
                "rio", "magrittr", "janitor", "did", 
                "panelView", "ggiplot", "binsreg", "interflex", 
                "vtable", "RPushbullet", "ggplot2", "LalRUtils" )

for ( pkg in needed_pack){
  remove.packages( pkg )
}


install.packages("devtools", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("magrittr", version = "2.0.3", dependencies = TRUE, repos = "https://cloud.r-project.org")
library(devtools)
devtools::update_packages(ask = FALSE)
devtools::install_github("apoorvalal/LalRUtils@718b20d0c601993c6385b8256dd40ff055b0a4e9")
install.packages("tidyverse", version = "3.4.2", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("data.table", version = "1.14.8", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("zoo", version = "1.8-12", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("tictoc", version = "1.2", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("fst", version = "0.9.6", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("fixest", version = "0.11.1", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("PanelMatch", version = "2.0.3", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("patchwork", version = "	1.1.2", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("rio", version = "0.5.29", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("janitor", version = "2.2.0", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("did", version = "2.1.2", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("panelView", version = "1.1.16", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("ggiplot", version = "0.3.0", dependencies = TRUE, repos = "https://grantmcdermott.r-universe.dev")
install.packages("binsreg", version = "0.9", dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages('interflex', version = "1.2.6", dependencies = TRUE, type = "source", repos = 'http://cran.us.r-project.org') 
install.packages("vtable", version = "1.4.4",  dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("RPushbullet", version = "0.3.4" , dependencies = TRUE, repos = "https://cloud.r-project.org")
install.packages("ggplot2", version = "3.4.2", dependencies = TRUE, repos = "https://cloud.r-project.org")



# Main Scripts 

source( "main_figure2.R" )
source( "main_figure3.R" )
source( "main_figure4.R" )
source( "main_figure4_table.R" )
source( "main_figure5.R" )
source( "main_figure5_table.R" )
source( "main_figure6.R" )
source( "main_figure6_tablePanelD.R" )
source( "main_figure7.R" )
source( "main_figure7_table.R" )
source( "main_figure8.R" )
source( "main_figure8_tablePanelB.R" )
source( "main_table1.R" )

# Appendix 

source("appendix_figureA1.R")
source("appendix_figureA2.R")
source("appendix_figureA3.R")
source("appendix_figureA3_table.R")
source("appendix_figureA4.R")
source("appendix_figureA4_table.R")
source("appendix_figureA6.R")
source("appendix_figureA6_tablePanelB.R")
source("appendix_figureA7.R")
source("appendix_tableA1.R")
source("appendix_tableA2.R")
source("appendix_tableA3.R")
source("appendix_tableA4.R")
source("appendix_tableA5.R")
source("appendix_tableA6.R")
source("appendix_tableA7.R")



